package com.example.demo.controller;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.example.demo.model.Employee;
import com.example.demo.service.EmployeeService;

@RequestMapping("emp")
@Controller
public class EmployeeController {
	@Resource
	private EmployeeService employeeService;
	
	@RequestMapping("all")
//	@ResponseBody
	public String findAll(Map<String,Object> map) {
		map.put("emps",employeeService.findAll());
		return "emp/all";
	}
	
	@GetMapping("update_view")
	public String updateView(@RequestParam("eid")Integer eid,Map<String, Object> map) {
		map.put("emp",employeeService.findById(eid));
		return "emp/update";
	}
	
	@GetMapping("update")
	public String updateView(Map<String, Object> map,Employee emp) {
		Boolean r=employeeService.update(emp);
		return "redirect:all";
		//http://localhost:8080/emp/all
		//http://localhost:8080/emp/update
	}
	
}
